package com.daodway.designpattern.commandpattern.undo;

import java.util.ArrayList;

public class ConcreteCommand implements Command{
	ArrayList<String> dirNameList;
	
	MakerDir makerDir;
	
	public ConcreteCommand(MakerDir makerDir) {
		super();
		dirNameList = new ArrayList<String>();
		this.makerDir = makerDir;
	}

	@Override
	public void execute(String name) {
		makerDir.createDir(name);
		dirNameList.add(name);
		System.out.println("创建目录:"+name);
	}

	@Override
	public void undo() {
		if(dirNameList.size()>0){
			int m = dirNameList.size();
			String str = dirNameList.get(m-1);
			makerDir.deleteDir(str);
			dirNameList.remove(m-1);
			System.out.println("撤销目录:"+str);
		}else
			System.out.println("没有需要撤销的操作!");
	}

}
